package com.wnhz.work.yz.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;

public class WenKuHtmlActivity extends BaseActivity implements View.OnClickListener {
    private WebView web;
//    private PDFView pdf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wen_ku_html);
        //pdf = (PDFView) findViewById(R.id.pdf);
        web = (WebView) findViewById(R.id.webview);
        initTitle();
        initData();
        initView();
    }

    private void initView() {
        if (url.toUpperCase().contains("PDF")) {
            //  initFdp();
        } else {
            initWeb();
        }
    }

//    private void initFdp() {
//        web.setVisibility(View.GONE);
//        pdf.setVisibility(View.VISIBLE);
//        pdf.fromUri(Uri.parse(url))
//                .defaultPage(num)
//                .onPageChange(this)
//                .enableAnnotationRendering(true)
//                .onLoad(this)
//                .onError(this)
//                .scrollHandle(new DefaultScrollHandle(this))
//                .load();
//        // MyToast(url);
////        pdf.fromUri(Uri.parse(url))
//////        or
//////        pdfView.fromFile(File)
//////        or
//////        pdfView.fromBytes(byte[])
//////        or
//////        pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
//////        or
//////        pdfView.fromSource(DocumentSource)
//////        or
//////        pdfView.fromAsset(String)
////                .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
////                .enableSwipe(true) // allows to block changing pages using swipe
////                .swipeHorizontal(false)
////                .enableDoubletap(true)
////                .defaultPage(0)
////                // allows to draw something on the current page, usually visible in the middle of the screen
//////                .onDraw(onDrawListener)
//////                // allows to draw something on all pages, separately for every page. Called only for visible pages
//////                .onDrawAll(onDrawListener)
//////                .onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
//////                .onPageChange(onPageChangeListener)
//////                .onPageScroll(onPageScrollListener)
//////                .onError(onErrorListener)
//////                .onRender(onRenderListener) // called after document is rendered for the first time
////                .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
////                .password(null)
////                .scrollHandle(null)
////                .enableAntialiasing(true) // improve rendering a little bit on low-res screens
////                // spacing between pages in dp. To define spacing color, set view background
////               // .spacing(0)
////                .load();
//    }

    private int num = 0;

    private void initWeb() {
        web.setVisibility(View.VISIBLE);
        // pdf.setVisibility(View.GONE);
        WebSettings settings = web.getSettings();
        settings.setJavaScriptEnabled(true);
//        settings.setUseWideViewPort(false);
//        settings.setJavaScriptCanOpenWindowsAutomatically(true);
//        settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

//        web.setWebViewClient(new WebViewClient() {
//            @Override
//            public void onPageFinished(WebView view, String url) {
//                //   handler.sendEmptyMessage(1);
//                super.onPageFinished(view, url);
//            }
//        });
//            webview.getSettings().setJavaScriptEnabled(true);

        web.loadUrl(url);
    }

    private String url;

    private void initData() {
        url = getIntent().getStringExtra("html");
        Log.e("uuuu", url);
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("文库详情");
        findViewById(R.id.btn_main_left).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
        }
    }


}
